<!DOCTYPE html>
<html>

<head>

	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">


	<title>泮河校区会议室预约系统</title>
	<meta name="keywords" content="H+后台主题,后台bootstrap框架,会员中心主题,后台HTML,响应式后台">
	<meta name="description" content="H+是一个完全响应式，基于Bootstrap3最新版本开发的扁平化主题，她采用了主流的左右两栏式布局，使用了Html5+CSS3等现代技术">

	<link rel="shortcut icon" href="favicon.ico">
	<link href="css/bootstrap.min.css-v=3.3.5.css"
		  tppabs="http://www.zi-han.net/theme/hplus/css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
	<link href="css/font-awesome.min.css-v=4.4.0.css"
		  tppabs="http://www.zi-han.net/theme/hplus/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
	<link href="css/plugins/iCheck/custom.css"
		  tppabs="http://www.zi-han.net/theme/hplus/css/plugins/iCheck/custom.css" rel="stylesheet">
	<link href="css/animate.min.css" tppabs="http://www.zi-han.net/theme/hplus/css/animate.min.css"
		  rel="stylesheet">
	<link href="css/style.min.css-v=4.0.0.css" tppabs="http://www.zi-han.net/theme/hplus/css/style.min.css?v=4.0.0"
		  rel="stylesheet">
	<!--    <base target="_blank">-->
	<link rel="stylesheet" type="text/css" href="./layui/css/layui.css"/>
	<style>
		#zhuti {
			height: 100%;

		}

		#zhuti::before {
			background: url('img/lg.jpg') no-repeat fixed center;
			background-size: 300px;
			content: "";
			opacity: 0.2;
			/*透明度设置*/
			width: 80%;
			height: 80%;
			position: absolute;
		}
	</style>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">

	<div class="row">
		<div class="col-sm-12">
			<div class="ibox float-e-margins" id="zhuti">
				<div class="ibox-title">
					<h3 style="font-weight: 600;margin-top: 0;">添加新物品</h3>
				</div>
				<form action="#" onsubmit="return false;">
					<div class="ibox-content">
						<div method="post" id="bigform" autocomplete="off" class="form-horizontal">
							<div class="form-group" style="margin-bottom: 0px;">
								<label class="col-sm-2 control-label">物品名称</label>
								<!-- col-sm-4 m-l-n -->
								<div class="col-sm-3">
									<input type="text" id="meetingName" required placeholder="请输入物品名称"
										   class="form-control">
								</div>
								<label class="col-sm-2 control-label">物品单位</label>
								<div class="col-sm-4">
									<input type="text" id="meetingPosi" required placeholder="请输入物品单位"
										   class="form-control">
								</div>
							</div>


							<div class="form-group" style="margin-bottom: 0px;">
								<div class="col-sm-4">
									<br>
									<button style="margin-left: 22%" class="btn-info" onclick="addSize()">添加物品规格
									</button>
									<br>
								</div>
							</div>

							<div id="sizeF">
								<div class="form-group">
									<label class="col-sm-2 control-label">物品规格</label>
									<!-- col-sm-4 m-l-n -->
									<div class="col-sm-3">
										<input type="text" required placeholder="请输入物品规格的有关信息"
											   class="form-control size">
									</div>
									<label class="col-sm-2 control-label">物品数量</label>
									<div class="col-sm-4">
										<input type="text" required placeholder="请输入该规格的数量"
											   class="form-control number">
									</div>
									<br>
								</div>
							</div>


							<!--                    物品图片-->
							<div class="form-group">



								<label class="col-sm-2 control-label">物品编号</label>
								<div class="col-sm-4">
									<input type="text" id="goodssign" name="sign" required placeholder="请输入物品的编号,以空格相隔"
										   class="form-control number">
								</div>

								<!--                                <div class="col-sm-2">-->
								<!--                                    <img id="img-pic"  src="img/0.png" alt="">-->
								<!--                                </div>-->

								<label class="col-sm-2 control-label">物品图片</label>
								<!-- col-sm-4 m-l-n -->
								<div class="col-sm-3">
									<button type="button" class="layui-btn" id="addpic">
										<i class="layui-icon">&#xe67c;</i>上传图片
									</button>
								</div>
							</div>
							<div class="hr-line-dashed"></div>
							<div class="form-group">
								<div class="col-sm-3 col-sm-offset-4">
									<button name="apply1" onclick="isNll()" style="margin-right: 30%;" id="tijiao"
											class="btn btn-primary"
									>添加
									</button>
									<button class="btn btn-white" id="reset1" type="reset" value="重新填写">重新填写</button>
								</div>
							</div>
						</div>
					</div>
				</form>

			</div>
		</div>
	</div>
</div>


<script src="./layui/layui.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery.min.js-v=2.1.4"
		tppabs="http://www.zi-han.net/theme/hplus/js/jquery.min.js?v=2.1.4"></script>
<script src="layui/layer/layer.js" type="text/javascript" charset="utf-8"></script>

<script src="js/bootstrap.min.js-v=3.3.5"
		tppabs="http://www.zi-han.net/theme/hplus/js/bootstrap.min.js?v=3.3.5"></script>
<script src="js/content.min.js-v=1.0.0"
		tppabs="http://www.zi-han.net/theme/hplus/js/content.min.js?v=1.0.0"></script>
<script src="js/plugins/iCheck/icheck.min.js"
		tppabs="http://www.zi-han.net/theme/hplus/js/plugins/iCheck/icheck.min.js"></script>

<script type="text/javascript" src="../../../tajs.qq.com/stats-sId=9051096"
		tppabs="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script>
<script>
    //页面加载函数入口
    $(document).ready(function () {

    });

    //添加一个物品规格
    function addSize() {
        let size = '<div class="form-group">\n' +
            '                                <label class="col-sm-2 control-label">物品规格</label>\n' +
            '                                <!-- col-sm-4 m-l-n -->\n' +
            '                                <div class="col-sm-3">\n' +
            '                                    <input type="text" required placeholder="请输入物品规格的有关信息"\n' +
            '                                           class="form-control size">\n' +
            '                                </div>\n' +
            '                                <label class="col-sm-2 control-label">物品数量</label>\n' +
            '                                <div class="col-sm-4">\n' +
            '                                    <input type="text" required placeholder="请输入该规格的数量"\n' +
            '                                           class="form-control number">\n' +
            '                                </div>\n' +
            '                                <br>\n' +
            '                            </div>'
        $('#sizeF').append(size);
    }

    //上传图片
    layui.use('upload', function () {
        var upload = layui.upload;
        //执行实例
        var uploadInst = upload.render({
            elem: '#addpic' //绑定元素
            , url: '/user/addImg' //上传接口
            , done: function (res) {
                //上传完毕回调
                console.log(res)
				alert(res)
                // $("#img-pic").attr("src",res)
            }
            , error: function () {
                //请求异常回调
            }
        });
    });

    //添加物品
    function thingAdd() {

        console.log(123)

        let inputG = $('input')
        inputG.each(function () {
            // console.log($(this))
            if ($(this)[0].value == '') {
                $(this).focus();
                layer.alert("输入框不能为空");
                return
            }
        })
        let name = inputG[0].value;
        let unit = inputG[1].value;
        //let allNum=$('#allNum').val();
        let sizeList = []
        let sizeG = $('#sizeF input')
		let sign=$("#goodssign").val()

        let number = 0
        for (let i = 0; i < sizeG.length; i += 2) {
            let sizeItem = {
                size: sizeG[i].value,
                num: parseInt(sizeG[i + 1].value),
                renum: parseInt(sizeG[i + 1].value)
            }
            sizeList.push(sizeItem)
            number += parseInt(sizeG[i + 1].value)
        }

        let thing = {
            name: name,
            num: parseInt(number),
            renum: parseInt(number),
			sign:sign,
            unit: unit,
            image: 'img/0.png',
            approve1: parseInt(number),
            approve2: 0,
            thingSizeList: sizeList
        }
        console.log(thing)
        $.ajax({
            type: "POST",
            url: "user/addThing",
            contentType: 'application/json',
            data: JSON.stringify(thing),
            success: function (msg) {
                console.log(msg)
                layer.alert(msg);
            },
            error: function (nn) {
                layer.alert(nn);
                console.log(nn);
            }
        });

        /* let name = $("#meetingName").val();
		 let posi = $("#meetingPosi").val();
		 let reso = $("#meetingResor").val();
		 let micro = $("#micro").val();
		 let wireless = $("#wireless").val();
		 let teacup = $("#teacup").val();
		 let maxSit = $("#maxSit").val()
		 console.log(name);
		 console.log(name == '' || posi == '' || reso == '' || micro == '' || wireless == '' || teacup == '' || maxSit == '')
		 if (name == '' || posi == '' || reso == '' || micro == '' || wireless == '' || teacup == '' || maxSit == '') {
			 layer.alert("输入框不能为空");
			 return
		 }
		 console.log(name, posi, reso, micro, wireless, teacup, maxSit)
		 $.ajax({
			 type: "POST",
			 url: "/admin/addMeeting",
			 data: {
				 name: name,
				 site: posi,
				 maxnum: parseInt(maxSit),
				 micro: parseInt(micro),
				 wireless: parseInt(wireless),
				 teacup: parseInt(teacup),
				 mes: reso
			 },
			 success: function (msg) {
				 console.log(msg)
				 layer.alert(msg);
			 },
			 error: function (nn) {
				 // layer.alert(nn);
				 console.log(nn);
			 },
		 });*/
    }

    //    输入框不能被控
    function isNll() {
        let list = $('input')
        for (let i = 0; i < list.length-1; i++) {
            console.log(list[i].value)
            if (list[i].value == "") {
                layer.alert('输入框不能为空哦')
                return;
            }
        }
        thingAdd();
    }
</script>
</body>

</html>
